package io.bluerain.ldrawersample;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import io.bluerain.ldrawersample.entities.Menu;

/**
 * Created by foredawn on 15-9-22.
 * 内容
 */
public abstract class ItemFragment extends Fragment {

    private int resource = -1;
    protected View root;

    public abstract void findRoot(View root);


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //修改子标题:
        ((AppCompatActivity) getActivity())
                .getSupportActionBar()
                .setSubtitle(getMenuItem().getText());
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        if (resource != -1) {
            root = inflater.inflate(resource, container, false);
            findRoot(root);
            return root;
        } else {
            return super.onCreateView(inflater, container, savedInstanceState);
        }
    }

    protected Menu menuItem;

    public Menu getMenuItem() {
        return menuItem;
    }

    public void setMenuItem(Menu menuItem) {
        this.menuItem = menuItem;
    }

    public int getResource() {
        return resource;
    }

    public void setResource(int resource) {
        this.resource = resource;
    }
}
